package com.design.model.flyweight;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @program: study
 * @className: FlyweightFactory
 * @description: TODO
 * @author: kukuxiahuni
 * @create: 2019-06-26 15:00
 * @version: v1.0
 **/
public class FlyweightFactory {

    private final ConcurrentHashMap<String, Flyweight> flyweightMap = new ConcurrentHashMap<>();

    public FlyweightFactory() {
        flyweightMap.putIfAbsent("x", new SharedFlyweight(1));
        flyweightMap.putIfAbsent("y", new SharedFlyweight(1));
        flyweightMap.putIfAbsent("z", new UnSharedFlyweight());
    }

    /**
     * 功能描述: TODO
     *
     * @param:
     * @return:
     * @auther: kukuxiahuni
     * @date: 2019/6/26 3:02 PM
     * @modify_auther: kukuxiahuni
     * @modify_time: 2019/6/26 3:02 PM
     **/
    public Flyweight get(String key) {
        return this.flyweightMap.getOrDefault(key, null);
    }
}
